package com.groupbuying.provider.service.impl;


import com.groupbuying.provider.dto.AccountDTO;
import com.groupbuying.provider.dto.StoreAccountDTO;
import com.groupbuying.provider.dto.convert.StoreAccountConvert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class StoreAccountConvertImpl implements StoreAccountConvert
{
    private static final Logger logger = LoggerFactory.getLogger(StoreAccountConvertImpl.class);
    @Override
    public List<AccountDTO> dos2dto(List<StoreAccountDTO> list) {
        if ( list == null ) {
            return null;
        }

        List<AccountDTO> list_ = new ArrayList<AccountDTO>();
        for ( StoreAccountDTO storeAccountDTO : list ) {
            logger.info("-----状态为-----,-----返回的Id为:{},{}",storeAccountDTO.getFreezeStatus(),storeAccountDTO.getAccountId());
            list_.add( do2dtos( storeAccountDTO ) );
        }

        return list_;
    }

    public AccountDTO do2dtos(StoreAccountDTO storeAccountDO) {
        if ( storeAccountDO == null ) {
            return null;
        }
        String freezeStatus = storeAccountDO.getFreezeStatus();
        logger.info("接收到的状态为:{}",freezeStatus);
        if(freezeStatus.equals("0")){
            freezeStatus="未冻结";
        }else{
            freezeStatus="已冻结";
        }
        AccountDTO accountDTO_ = new AccountDTO();

        accountDTO_.setFreezeStatus( freezeStatus );
        accountDTO_.setAgentName( storeAccountDO.getAgentName() );
        accountDTO_.setId( storeAccountDO.getId() );
        accountDTO_.setAccountId( storeAccountDO.getAccountId() );
        accountDTO_.setOper( storeAccountDO.getOper() );
        accountDTO_.setOperTime( storeAccountDO.getOperTime() );
        accountDTO_.setDelFlag( storeAccountDO.getDelFlag() );
        accountDTO_.setCreateOper( storeAccountDO.getCreateOper() );
        accountDTO_.setCreateOpeTime( storeAccountDO.getCreateOpeTime() );
        accountDTO_.setAccountName( storeAccountDO.getAccountName() );
        accountDTO_.setPassword( storeAccountDO.getPassword() );
        accountDTO_.setEmail( storeAccountDO.getEmail() );
        accountDTO_.setMobile( storeAccountDO.getMobile() );
        accountDTO_.setStatus( storeAccountDO.getStatus() );
        accountDTO_.setProviderId( storeAccountDO.getProviderId() );
        List<String> list = bigIntegerListToStringList( storeAccountDO.getRoleIds() );
        if ( list != null ) {
            accountDTO_.setRoleIds( list );
        }
        accountDTO_.setName( storeAccountDO.getName() );
        accountDTO_.setProviderName( storeAccountDO.getProviderName() );
        accountDTO_.setAgentId( storeAccountDO.getAgentId() );

        return accountDTO_;
    }

    private DecimalFormat createDecimalFormat(String numberFormat ) {

        DecimalFormat df = new DecimalFormat( numberFormat );
        df.setParseBigDecimal( true );
        return df;
    }

    protected List<String> bigIntegerListToStringList(List<BigInteger> list) {
        if ( list == null ) {
            return null;
        }

        List<String> list_ = new ArrayList<String>();
        for ( BigInteger bigInteger : list ) {
            list_.add( bigInteger.toString() );
        }

        return list_;
    }
}
